let readlineSync = require('readline-sync');
let menu = require('./menu');
let addStudent = require('./addStudent');
let printReport = require('./printReport');

module.exports = function main() {
    let students = [];
    let student_obj;
    menu();
    let choice = readlindSync.question();
    while(choice !== '3'){
        if(choice === '1'){
            console.log(`请输入学生信息（格式：姓名, 学号, 民族, 班级, 学科: 成绩, ...），按回车提交：`);
            let studentInfo = readlineSync.question(``);        
            student_obj = addStudent(studentInfo);
            students.push(student_obj);
        }else if(choice === '2'){
            console.log(`请输入要打印的学生的学号（格式： 学号, 学号,...），按回车提交：`);
            let id = readlineSync.question(``);
            while(!(/^\d{4}$/).test(id)){
                console.log(`请按正确的格式输入要打印的学生的学号（格式： 学号, 学号,...），按回车提交：`);
                id = readlineSync.question(``);
            }
            printReport(students,id);
        }
        menu();
        choice = readlindSync.question();
    }
    console.log('已退出');
    return 0;

}